/**
 * 
 */
package fr.cephb.operon.server.ws;

import java.io.File;

import javax.annotation.Resource;
import javax.jws.WebService;
import javax.servlet.ServletContext;
import javax.xml.ws.WebServiceContext;
import javax.xml.ws.handler.MessageContext;

import fr.cephb.joperon.core.bio.Assembly;

/**
 * SNPToolWeb version of SnpToolImpl used to be deployed in a web server
 *
 */
@WebService(endpointInterface="fr.cephb.operon.server.ws.SnpTool")
public class SNPToolWeb
	implements SnpTool
	{
	@Resource
	private WebServiceContext wsContext;
	/** initilized ? */
	private BasicSnpTool delegate=null;
	 
	
	private BasicSnpTool getDelegate() throws Exception
		{
		if(delegate!=null) return delegate;
		delegate= new BasicSnpTool()
			{
			};
		if(wsContext==null) throw new IllegalStateException("WebServiceContext was not injected ??!!");
		MessageContext ctxt = wsContext.getMessageContext();
		ServletContext ctx = (ServletContext)ctxt.get(MessageContext.SERVLET_CONTEXT);
		
		
		
		String as=ctx.getInitParameter("assembly");
		if(as!=null)
			{
			delegate.setAssembly(Assembly.getAssemblyById(Integer.parseInt(as)));
			}
		String db_home=ctx.getInitParameter("db_home");
		if(db_home!=null)
			{
			delegate.setBerkeleyDBDir(new File(db_home));
			}
		
		String s= ctx.getInitParameter("limit");
		if(s!=null)
			{
			delegate.setLimitSnpCount(Integer.parseInt(s));
			}
		return delegate;
		}

	@Override
	public String getAssemblyName() throws Exception {
		return getDelegate().getAssemblyName();
	}

	@Override
	public SNP[] getSNPByName(String rsName) throws Exception {
		return getDelegate().getSNPByName(rsName);
	}

	@Override
	public SNP[] getSNPByPosition(String krom, int start, int end)
			throws Exception {
		return getDelegate().getSNPByPosition(krom, start, end);
	}
	
	
	}

